import { autoload, onDOMContentLoaded } from '@cydon/ui'
import '@cydon/ui/components/ImportHTML'
import '@cydon/ui/src/c-message.styl'

// 组件
const components = import.meta.glob('./components/*.ts')

onDOMContentLoaded(() => {
	// 自动加载组件
	autoload(document.body, async name => {
		try {
			return name === 'RelativeTime' ? import('@github/relative-time-element') :
				name === 'CAsync' ? import('@cydon/ui/components/CAsync') :
				name === 'TabContainer' ? import('@cydon/ui/components/TabContainer') :
				components[`./components/${name}.ts`]()
		} catch (e) {
			console.error(name, e)
			throw e
		}
	}, false)
})
